package com.example.NeteaseCloudMusicApi.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.NeteaseCloudMusicApi.R;
import com.example.NeteaseCloudMusicApi.entity.Player;

import java.util.List;

public class PlayerAdapter extends RecyclerView.Adapter<PlayerAdapter.ViewHolder> {

    private List<Player> mPlayerList;

    public PlayerAdapter (List<Player> playerList){
        mPlayerList = playerList;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_pager_content,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Player player = mPlayerList.get(position);
        holder.playerImage.setImageResource(player.getImage());
        holder.playerName.setText(player.getName());
    }

    @Override
    public int getItemCount() {
        return mPlayerList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView playerImage;
        TextView playerName;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            playerImage = itemView.findViewById(R.id.showImage_start);
            playerName = itemView.findViewById(R.id.song_list_introduction);

        }
    }
}
